package com.ruoyi.locate.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.locate.domain.WWarehouseMapGrid;
import com.ruoyi.locate.service.IWWarehouseMapGridService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 仓位网格Controller
 * 
 * @author ruoyi
 * @date 2025-01-06 17:39:13
 */
@RestController
@RequestMapping("/locates/grid")
public class WWarehouseMapGridController extends BaseController
{
    @Autowired
    private IWWarehouseMapGridService wWarehouseMapGridService;

    /**
     * 查询仓位网格列表
     */
    @PreAuthorize("@ss.hasPermi('locates:grid:list')")
    @GetMapping("/list")
    public TableDataInfo list(WWarehouseMapGrid wWarehouseMapGrid)
    {
        startPage();
        List<WWarehouseMapGrid> list = wWarehouseMapGridService.selectWWarehouseMapGridList(wWarehouseMapGrid);
        return getDataTable(list);
    }

    /**
     * 导出仓位网格列表
     */
    @PreAuthorize("@ss.hasPermi('locates:grid:export')")
    @Log(title = "仓位网格", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, WWarehouseMapGrid wWarehouseMapGrid)
    {
        List<WWarehouseMapGrid> list = wWarehouseMapGridService.selectWWarehouseMapGridList(wWarehouseMapGrid);
        ExcelUtil<WWarehouseMapGrid> util = new ExcelUtil<WWarehouseMapGrid>(WWarehouseMapGrid.class);
        util.exportExcel(response, list, "仓位网格数据");
    }

    /**
     * 获取仓位网格详细信息
     */
    @PreAuthorize("@ss.hasPermi('locates:grid:query')")
    @GetMapping(value = "/{gridId}")
    public AjaxResult getInfo(@PathVariable("gridId") Long gridId)
    {
        return success(wWarehouseMapGridService.selectWWarehouseMapGridByGridId(gridId));
    }

    /**
     * 新增仓位网格
     */
    @PreAuthorize("@ss.hasPermi('locates:grid:add')")
    @Log(title = "仓位网格", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody WWarehouseMapGrid wWarehouseMapGrid)
    {
        wWarehouseMapGrid.setCreateBy(getNickName());
        return toAjax(wWarehouseMapGridService.insertWWarehouseMapGrid(wWarehouseMapGrid));
    }

    /**
     * 修改仓位网格
     */
    @PreAuthorize("@ss.hasPermi('locates:grid:edit')")
    @Log(title = "仓位网格", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody WWarehouseMapGrid wWarehouseMapGrid)
    {
        wWarehouseMapGrid.setUpdateBy(getNickName());
        return toAjax(wWarehouseMapGridService.updateWWarehouseMapGrid(wWarehouseMapGrid));
    }

    /**
     * 删除仓位网格
     */
    @PreAuthorize("@ss.hasPermi('locates:grid:remove')")
    @Log(title = "仓位网格", businessType = BusinessType.DELETE)
	@DeleteMapping("/{gridIds}")
    public AjaxResult remove(@PathVariable Long[] gridIds)
    {
        return toAjax(wWarehouseMapGridService.deleteWWarehouseMapGridByGridIds(gridIds));
    }

    /**
     * 获取仓位栅格详细信息
     */
    //@PreAuthorize("@ss.hasPermi('locates:grid:query')")
    @GetMapping(value = "/data/{parentId}")
    public AjaxResult getMapGrid(@PathVariable("parentId") Long parentId)
    {
        return success(wWarehouseMapGridService.selectWWarehouseMapGridByparentId(parentId));
    }
}
